﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLBH.DataModel;
using QLBH.Base;
using QLBH.Model.Controller;
using QLBH.ModelInterface;

namespace QLBH.FeatureModel
{
    public class QLNhomHangModel:IQLNhomHangModel
    {
        public Guid ID { set; get; }
        public String MaLH { set; get; }
        public String TenLH { set; get; }
        public String Mota { set; get; }
        public String GhiChu { set; get; }
        public DateTime NgayTao { set; get; }
        public Guid NganhHangID { set; get; }
        public String TenNH { set; get; }
        public void InitFromEntity(LOAIHANG entity)
        {
            ID = entity.LOAIHANGID;
            MaLH = entity.LOAIHANGCODE;
            TenLH = entity.TENLOAIHANG;
            Mota = entity.MOTA;
            GhiChu = entity.GHICHU;
            NgayTao = (DateTime)entity.CREATED;
            NganhHangID = (Guid)entity.NGANHHANGID;

            var nh = NganhHangController.GetInstance().FindBy(it => it.ID == NganhHangID).FirstOrDefault();
            if (nh!=null)
            {
                TenNH = nh.TENNH;
            }
            
        }

        public LOAIHANG ToEntity()
        {
            LOAIHANG entity = new LOAIHANG();
            entity.LOAIHANGID = ID;
            entity.TENLOAIHANG = TenLH;
            entity.LOAIHANGCODE = MaLH;
            entity.MOTA = Mota;
            entity.GHICHU = GhiChu;
            entity.CREATED = (DateTime)NgayTao;
            entity.NGANHHANGID = NganhHangID;

            return entity;
        }
    }
}
